package io.github.source.bean;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: Doh
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author: huangrongcai
 * @date: 2024/6/4
 * @Copyright: 黄嵘才（HuangRc)
 */
public class Doh {

    @SerializedName("name")
    private String name;
    @SerializedName("url")
    private String url;
    @SerializedName("ips")
    private List<String> ips;


    public static List<Doh> get(Context context) {
//        List<Doh> items = new ArrayList<>();
//        String[] urls = context.getResources().getStringArray(com.github.catvod.crawler.R.array.doh_url);
//        String[] names = context.getResources().getStringArray(com.github.catvod.crawler.R.array.doh_name);
//        for (int i = 0; i < names.length; i++) items.add(new Doh().name(names[i]).url(urls[i]));
//        return items;

        return new ArrayList<>();
    }

    public static Doh objectFrom(String str) {
        Doh item = new Gson().fromJson(str, Doh.class);
        return item == null ? new Doh() : item;
    }

    public static List<Doh> arrayFrom(JsonElement element) {
        Type listType = new TypeToken<List<Doh>>() {
        }.getType();
        List<Doh> items = new Gson().fromJson(element, listType);
        return items == null ? new ArrayList<>() : items;
    }

    public Doh name(String name) {
        this.name = name;
        return this;
    }

    public Doh url(String url) {
        this.url = url;
        return this;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public List<String> getIps() {
        return ips;
    }

    public void setIps(List<String> ips) {
        this.ips = ips;
    }
}
